
use "grant_ineligible_data.dta", clear

{ // Defining variables, locals, other setup
local leftquote "\\\`"


local lightest "white"
local darker "gs11" 
local darkest "gs4"
local cap_color "black"

local L6_color "`darker'"
local L_border "white"
gen got_loanbump6 = (treatment == 2)

gen loanbump_amount = 0
replace loanbump_amount = 600 if got_loanbump6 == 1

foreach i in 	loanbump_amount				///
				  {
  replace `i' = `i'/100
}



gen year = cohort
replace year = 2016 if cohort == 2016.5

local cons_lab "Constant"

rename (*loanbump*) (*LB*)

label variable ec "Exp. Contribution"

label variable LoanAmount "TGL Loan"

local LB_amount_lab "Extra Loans (\\\$100s)"
local LB_amount_b_lab "Extra Loans (\\\$100s)"
local LB_amount_int_lab "Extra Loans"
local LB_amount_lab_wUnit "Extra Loans (\\\$100s)"
local LB_amount_b_lab_wUnit "Extra Loans (\\\$100s)"

gen loanbump_amount = 0
replace loanbump_amount = 600 if got_LB6 == 1

gen ControlLoan = (LoanAmount*100 - loanbump_amount)

recode treatment (0=0) (1=2) (2=1) (3=3) (4=5) (5=4)
label def treatment_recode 0 "C" 1 "L6" 2 "G6" 3 "G12" 4 "G18" 5 "L18"
label values treatment treatment_recode

}

***** TABLE A1: Treatment Effects of Additional Loans, Grant-Ineligible Applicants (2015–2016)
{
local depvar FDOS

local xvars LB_amount
local regs 1
local cond "year < 2017"

foreach r in `regs' {
	local extra_vars ""
	if `r' == 2 local extra_vars "${demos}"
	qui xi: areg `depvar' `xvars'  `extra_vars'   if `cond', 	///
									absorb(Batch) r
	matrix define A = r(table)
	local N_`r': display %3.0f `e(N)'
	local r2_`r': display %3.2f `e(r2)'
	qui sum `depvar' if e(sample) == 1
	local ymean_`r': display %3.2f `r(mean)'		
	local i = 0
	foreach var in `xvars'   cons {
		local i = `i' + 1
		if "`var'" == "cons" local i = colsof(A)
		local b_`var'_`r': display %3.2f A[1, `i']
		local se_`var'_`r': display %3.2f A[2, `i']
		local p_`var'_`r' = A[4, `i']
		local s_`var'_`r' = ""
		if `p_`var'_`r'' < .1 {
			local s_`var'_`r' = "`s_`var'_`r''" + "*"
		}
		if `p_`var'_`r'' < .05 {
			local s_`var'_`r' = "`s_`var'_`r''" + "*"
		}
		if `p_`var'_`r'' < .01 {
			local s_`var'_`r' = "`s_`var'_`r''" + "*"
		}
	}	
}

local regs 1 2

file open tex using "TableA1.tex", write replace
foreach var in `xvars'   {
	file write tex  "``var'_b_lab'"
	foreach r in `regs' {
		file write tex "& `b_`var'_`r''`s_`var'_`r''"
	}
	file write tex " \\" _n
	file write tex  "``var'_se_lab'"
	foreach r in `regs' {
		if "`se_`var'_`r''" != "" {
			file write tex `"& (`se_`var'_`r'')"'
		}
		else {
			file write tex `"& "'
		}
	}
	file write tex " \\" _n
}
file write tex "Demographics"
file write tex " & No & Yes "

file write tex " \\" _n "Batch FEs "
foreach r in `regs' {
		file write tex " & Yes "
}
file write tex " \\" _n "\$N\$"
foreach r in `regs' {
	file write tex " & `N_`r''"
}

file write tex " \\" _n "\$R^2\$"
foreach r in `regs' {
		file write tex " & `r2_`r''"
}
file write tex " \\" _n "Mean of Dependent Variable"
foreach r in `regs' {
	file write tex " & `ymean_`r''"
}
file write tex " \\ \hline"
file close tex

include clear_locals.do
}

***** FIGURE A1: Control Awards, Grant-Ineligible Applicants (2015–2016)
{
hist ControlLoan, xtitle("Loans")				///
		graphregion(color(white)) percent width(125) lcolor(`L_border') lwidth(vthin) fcolor(`L6_color')	///
		start(0) xlabels(0(500)2000) ///
		scale(1.5) legend(off) 
graph export "FigureA1.pdf", as(pdf) replace
}
		
